#!/usr/bin/python

#Author: Maulik Kapuria
import os
import random

class Deck(object):
	"""Attribute: None"""
	"""This is a Deck Class. It has a constructor that generates a deck of 52 cards and returns a list. it has a str method for printing the deck. and it also has a shuffle method for shuffling the cards in the deck"""
	def __init__(self): 
		self.cards = []
		for suit in range(4): 
			for rank in range(1, 14):
				card = Card(suit, rank) 
				self.cards.append(card)

	def __str__(self): 
		res=[]
		for card in self.cards: 
			res.append(str(card))
		return '\n'.join(res)

	def shuffle(self): 
		random.shuffle(self.cards)


class Card(object):
	"""Attribute: Suit & Card"""
	"""This is a Card Class. It has a constructor that takes the suit and rank and returns a card.. it has a str method for printing the card. It had a compare methd to compare between two cards"""

	suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades'] 
	rank_names = [None, 'Ace', '2', '3', '4', '5', '6', '7','8', '9', '10', 'Jack', 'Queen', 'King']

	def __init__(self, suit=0, rank=2): 
		self.suit = suit 
		self.rank = rank

	def __str__(self): 
		return '%s of %s' % (Card.rank_names[self.rank],Card.suit_names[self.suit])


	def __cmp__(self, other): 
		t1 = self.suit, self.rank 
		t2 = other.suit, other.rank 
		return cmp(t1, t2)

def clrscr():
	"""This function clears the screen according to the OS it is on."""
	if os.name == "posix":
		os.system('clear')
	else:
		os.system('CLS')

def main ():
	"""This is the main function"""
	clrscr()
	
	print "*******************************************************************\n"
	mydeck_o = Deck()
	mydeck_o.shuffle()
	mydeck_o.cards.sort()
	print mydeck_o  
	print "*******************************************************************\n"
	

if __name__ == '__main__':
	main()
